package com.aboverock.module.system.validator.constraintvalidators;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.aboverock.common.enums.UserTypeEnum;
import com.aboverock.module.system.validator.constraints.UserTypeLimit;

/**
 * The Class UserTypeLimitValidator.
 *
 * @author Rock Wang
 */
public class UserTypeLimitValidator implements ConstraintValidator<UserTypeLimit, Integer> {

    private UserTypeEnum limitValue;

    @Override
    public void initialize(UserTypeLimit constraintAnnotation) {
        limitValue = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (value != null && value.equals(limitValue.getValue())) {
            return true;
        }
        
        return false;
    }

}
